from pathlib import Path

from setuptools import Extension, find_packages

from Cython.Build import cythonize

example_modules = [
    # pub share c wrapper
    Extension(
        "example_extra_extension.example_py",
        sources=[
            "example_extra_extension/example_py.pyx",
        ],
    ),
]


class BuildFailed(Exception):
    pass


def build(setup_kwargs: dict):
    setup_kwargs.update({
        "packages": find_packages(),
        "ext_modules": cythonize(
            example_modules,
            language_level="3",
            show_all_warnings=True,
            # 如果提示pxd查找失败这里添加即可
            include_path=[Path.cwd().joinpath(".venv", "Lib", "site-packages").__str__()],
        ),
        # 将编译结果复制回本模块，方便测试
        "script_args": ["build_ext", "--inplace"],
    })
